package me.evis.gae.test;

import com.google.appengine.api.datastore.dev.LocalDatastoreService;
import com.google.appengine.tools.development.ApiProxyLocalImpl;
import com.google.apphosting.api.ApiProxy;

/**
 * Unit tests against GAE DataStore services based classes should extend this 
 * test case to get AppID registered.
 * Data will be cleaned after a test.
 */
public class LocalDataStoreTestCase extends LocalServiceTestCase {
    
    final void initLocalService() {
        super.initLocalService();
        ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate();
        proxy.setProperty(LocalDatastoreService.NO_STORAGE_PROPERTY,
                          Boolean.TRUE.toString());
    }

    final void cleanLocalService() {
        ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate();
        LocalDatastoreService datastoreService = 
            (LocalDatastoreService) proxy.getService("datastore_v3");
        // Clean all data after a single unit test.
        datastoreService.clearProfiles();
        super.cleanLocalService();
    }
}
